/*  File Name	: SvcHandler.cpp
 *  Author		: Pang Jiacai
 *	 E-mail		: 823960168@qq.com
 *  Created on	: 2012-4-25
 *  Description:
 */

#include "SvcHandler.h"
#include "Reactor.h"

SvcHandler::SvcHandler(Reactor *reactor)
{
	this->reactor(reactor);
	this->is_closing_ = false;
}

SvcHandler::~SvcHandler()
{

}

int SvcHandler::open (Reactor *reac)
{
	if(NULL!=reac)
	{
		this->reactor(reac);
	}
	if(NULL==this->reactor())
	{
		return -1;
	}
	if(this->reactor()->register_handler(this->peer()->get_handle(),
			this,EventHandler::READ_MASK)<0)
	{
		LOG((DEBUG_LOG,"SvcHandler::open-->register_handler error"));
		return -1;
	}
	return 0;
}

int SvcHandler::close(ulong flags)
{
	return this->handle_close();
}

void SvcHandler::set_handle (int handle)
{
	this->peer_.set_handle(handle);
}

int SvcHandler::get_handle (void) const
{
	return this->peer_.get_handle();
}

int SvcHandler::handle_input(int handle)
{
	LOG((DEBUG_LOG,"SvcHandler::handle_input"));
	return 0;
}

int SvcHandler::handle_close (int handle,ReactorMask mask)
{
	return this->peer()->close();
}

SockStream *SvcHandler::peer(void)
{
	return &this->peer_;
}
